﻿String.prototype.endsWith = function (str) {
    return (this.match(str + "$") == str);
}
//==========================String.Format========================
function _StringFormatInline() {
    var txt = this;
    for (var i = 0; i < arguments.length; i++) {
        var exp = new RegExp('\\{' + (i) + '\\}', 'gm');
        txt = txt.replace(exp, arguments[i]);
    }
    return txt;
}

function _StringFormatStatic() {
    for (var i = 1; i < arguments.length; i++) {
        var exp = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        arguments[0] = arguments[0].replace(exp, arguments[i]);
    }
    return arguments[0];
}

if (!String.prototype.format) {
    String.prototype.format = _StringFormatInline;
}

if (!String.format) {
    String.format = _StringFormatStatic;
}

//How to use : 
//Static
//var str = String.format("This is a {0} string using the {1} method.","formatted","static");
//inline
//var str = "This is a {0} string using the {1} method.".format("formatted", "inline");

//==========================End String.Format========================

// Nedd include jquery before use this class
HieuLe.JS.DetailTab = function (containerId, buttonAddId, buttonSearchId,
                               buttonCancelId, buttonClearId, tabAddId,
                               tabSearchId, tabToggleId, slideTimes) {
    if (containerId) {
        this.Container = String.format("[id$='{0}']", containerId);
    }

    if (buttonAddId)
        this.ButtonAdd = String.format("[id$='{0}']", buttonAddId);

    if (buttonSearchId)
        this.ButtonSearch = String.format("[id$='{0}']", buttonSearchId);

    if (buttonCancelId)
        this.ButtonCancel = String.format("[id$='{0}']", buttonCancelId);

    if (buttonClearId)
        this.ButtonClear = String.format("[id$='{0}']", buttonClearId);

    if (tabAddId)
        this.TabAdd = String.format("[id$='{0}']", tabAddId);

    if (tabSearchId)
        this.TabSearch = String.format("[id$='{0}']", tabSearchId);

    if (tabToggleId)
        this.TabToggle = String.format("[id$='{0}']", tabToggleId);

    this.SlideTimes = 500;
    if (slideTimes)
        this.SlideTimes = slideTimes;

    this.ToggleContainer = function () {
        var command = $(this.TabToggle).attr("href").replace(/javascript:/g, "");
        if ($(this.Container).is(":visible")) {
            window.setTimeout(command, this.SlideTimes);
            $(this.Container).slideToggle(this.SlideTimes);
        }
        else {
            window.setTimeout(command, 1);
            $(this.Container).slideToggle(this.SlideTimes);
        }
        return false;
    };

    this.DisplayAddForm = function () {
        var command = $(this.TabAdd).attr("href").replace(/javascript:/g, "");
        window.setTimeout(command, 1);
        if (!$(this.Container).is(":visible"))
            $(this.Container).slideToggle(this.SlideTimes);

        $(this.TabAdd).parent().addClass('current');
        $(this.TabSearch).parent().removeClass()
        return false;
    };

    this.DisplaySearchForm = function () {
        var command = $(this.TabSearch).attr("href").replace(/javascript:/g, "");
        window.setTimeout(command, 1);
        if (!$(this.Container).is(":visible"))
            $(this.Container).slideToggle(this.SlideTimes);

        $(this.TabSearch).parent().addClass('current');
        $(this.TabAdd).parent().removeClass();
        return false;
    };
};

var js_DetailTab = new HieuLe.JS.DetailTab('Panel_TabDetail', 'LinkButton_Add', 'LinkButton_Search', 'LinkButton_Cancel', 'LinkButton_Clear', 'LinkButton_TabAdd', 'LinkButton_TabSearch', 'LinkButton_TabToggle', 500);



///////////////// Ready Function \\\\\\\\\\\\
$(document).ready(function () {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    InitInputMask();   
});

function EndRequestHandler() {
    InitInputMask();
}

function InitInputMask() {
    $("input[rel='date']").mask("99/99/9999");
    $("input[rel='date-time']").mask("99/99/9999 99:99:99");

    $("input[rel='uint']").jStepper({ minValue: 0, maxValue: 2000000000, allowDecimals: false, disableNonNumeric: true });
    $("input[rel='u2num']").jStepper({ minValue: 1, maxValue: 99, allowDecimals: false, disableNonNumeric: true });
    $("input[rel='ufloat']").jStepper({ minValue: 0, maxValue: 23, allowDecimals: true, minDecimals: 0, maxDecimals: 1000000000000000, disableNonNumeric: true });
}

///////////////// End Ready Function \\\\\\\\\\\\